package com.binvshe.binvshe.organization;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.binvshe.binvshe.R;
import com.binvshe.binvshe.common.image.IML;
import com.binvshe.binvshe.organization.entity.OrgTypeEntity;
import com.bumptech.glide.Glide;
import com.pachong.android.baseuicomponent.adapter.RecyclerViewBaseAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2017/2/4
 */

public class TypeAdapter extends RecyclerViewBaseAdapter<OrgTypeEntity> {


    public TypeAdapter(Context con) {
        super(con);
    }

    @Override
    public RecyclerView.ViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        return new TypeHolder(setAdapterViewItem(parent, R.layout.item_org_type));
    }

    @Override
    public void onBindHolder(RecyclerView.ViewHolder holder, int position) {
        OrgTypeEntity data = getData().get(position);
        TypeHolder vh = (TypeHolder) holder;
        Glide.with(getContext()).load(data.getIcon()).into(vh.mIvTypeIcon);
        vh.mTvTypeName.setText(data.getTypeName());
        setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ClubSearchResultActivity.start(
                        getContext(), ClubSearchResultActivity.USE_TYPEID,
                        getData().get(i).getId(), getData().get(i).getTypeName()
                );
            }
        });
    }

    class TypeHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.ivTypeIcon)
        ImageView mIvTypeIcon;
        @Bind(R.id.tvTypeName)
        TextView mTvTypeName;

        public TypeHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}